package com.btl.service.ai.support.rag.scoring;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Configuration
public class ScoringStrategyFactory {

    @Resource
    private ApplicationContext applicationContext;

    private static final Map<ScoringModelEnum, ScoringStrategy> strategyMap = new ConcurrentHashMap<>();


    @PostConstruct
    void init() {
        Collection<ScoringStrategy> values = applicationContext.getBeansOfType(ScoringStrategy.class)
                .values();
        for (ScoringStrategy value : values) {
            strategyMap.put(value.model(), value);
        }
    }

    public static ScoringStrategy getStrategy(ScoringModelEnum modelEnum) {
        return strategyMap.getOrDefault(modelEnum, strategyMap.get(ScoringModelEnum.LOCAL_BGE_RERANK_SCORING_MODEL));
    }

}
